/*  Copyright (C) 2012 Vladimir M. <mlvl.jr@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; by version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

import QtQuick 2.0

Canvas {
    property bool armed

    property color unarmedColor: "green"
    property color armedColor: "red"

    property real marginToRadiusRatio: 0.92
    property real lineWidthToRadiusRatio: 0.130

    property real minutesTime

    antialiasing: true

    onPaint: {
        var ctx = getContext('2d')
        ctx.clearRect(0, 0, width, height)

        if (minutesTime <= 0.0)
            return

        ctx.save()

        ctx.beginPath()

        var angle = -Math.PI/2 + minutesTime/60*2*Math.PI
        var angleWidth = Math.PI/10
        var radius = parent.width/2*marginToRadiusRatio

        ctx.arc(parent.width/2, parent.height/2,
                radius,
                angle - angleWidth, angle)

        context.lineWidth = lineWidthToRadiusRatio*radius
        context.strokeStyle = armed? armedColor: unarmedColor

        context.stroke();

        ctx.restore()
    }

    onMinutesTimeChanged: requestPaint()

    onArmedChanged: {
//        console.log("armedChanged")
        requestPaint()
    }
}
